<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Layout
 *
 * @author Fab
 */
class Plugin_Layout extends Zend_Controller_Plugin_Abstract {

    /**
     * Called before an action is dispatched by Zend_Controller_Dispatcher.
     *
     * This callback allows for proxy or filter behavior.  By altering the
     * request and resetting its dispatched flag (via
     * {@link Zend_Controller_Request_Abstract::setDispatched() setDispatched(false)}),
     * the current action may be skipped.
     *
     * @param  Zend_Controller_Request_Abstract $request
     * @return void
     */
    public function preDispatch(Zend_Controller_Request_Abstract $request)
    {

        $module = $request->getModuleName();
        # Instencie le layout si moduleName est différent de "default"
        $layout = Zend_Layout::getMvcInstance();

        // check module and automatically set layout
        $layoutsDir = $layout->getLayoutPath();

        // check if module layout exists else use default
        if(file_exists($layoutsDir . DIRECTORY_SEPARATOR . $module . ".phtml")) {
            $layout->setLayout($module);
        } else {
            $layout->setLayout("layout");
        }
        $view = $layout->getView();
        # host
        $view->host = 'http://' . $_SERVER['HTTP_HOST'] . '/';
   }

   public function  postDispatch(Zend_Controller_Request_Abstract $request) {
        $response = $this->getResponse();
        $view = new Zend_View();
//        $view->setBasePath(APPLICATION_PATH.'layouts/scripts');

       // $response->append('footer', $view->render('footer.phtml'));
    }

   public function dispatchLoopShutdown()
   {
   }

}
?>
